import { Button } from 'antd';
import { toJS } from 'mobx';
import { inject, observer} from 'mobx-react';
import {routerShape} from 'react-router';
import {WeaTop,WeaRightMenu,WeaLocaleProvider,WeaNewScroll,WeaTools} from 'ecCom'
import { ConditionNum } from '../list/listCondition'
const getLabel = WeaLocaleProvider.getLabel;

@inject("proStore")
@observer
class ProSearch extends React.Component {
    static contextTypes = {
        router: routerShape
    }
    constructor(props) {
        super(props);
    }
    componentDidMount  = () => {
        const {proStore} = this.props;
        //设置dataType
        const preDataType = this.props.location.query.dataType || "3";
        proStore.setDataType(preDataType);
        proStore.init({ "isSuper":"1","isSuperPage":true,"fromSuperPage":false,"selectedTreeKey":"0",pageFrom:"project",dataType:preDataType});
    }
    componentWillReceiveProps = (nextProps) => {
        if(nextProps.location.key != this.props.location.key){
            const {proStore} = nextProps;
            //设置dataType
            const nextDataType = nextProps.location.query.dataType || "3";
            proStore.setDataType(nextDataType);
            proStore.init({ "isSuper":"1","isSuperPage":true,"fromSuperPage":false,"selectedTreeKey":"0",pageFrom:"project",dataType:nextDataType});
        }
    }

    render() {
        const {proStore} = this.props;
        const {status,tasklabels,form,formB} = proStore;
        const {loading} = status;
        const {topIcon="icon-coms-government" ,iconBgcolor="#f14a2d"} = tasklabels;
        let height = document.body.clientHeight;
        return (
            <div className='g-proSearch'>
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@zu0eua`} datas={this.getRightMenu()} style={{color:"#ccc"}}>
                    <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@i12cdf`} loading={loading} icon={<i className={topIcon} />} iconBgcolor={iconBgcolor} title={getLabel('21223,386772',"督办查询")} style={{'height':height-115,'overflow': 'auto'}}>
                        <div className='g-proSearch-condition'>
                        {/* <WeaNewScroll height={height-80}> */}
                           <ConditionNum ecId={`${this && this.props && this.props.ecId || ''}_ConditionNum@xg7h5a`} listStore={proStore} type="search" formB={formB} col={2} onEnterSearch={this.forwardQueryResult.bind(this)} forceRefresh={this.forceRefresh.bind(this)}></ConditionNum>
                         {/* </WeaNewScroll> */}
                        </div>
                        <div className='g-proSearch-btns'>
                            {this.getSearchButtons()}
                        </div>
                    </WeaTop>
                </WeaRightMenu>
            </div>
        )
    }
    forceRefresh =(param) =>{
        // const {proStore} = this.props;
        // const {conditionNum,formB} = proStore;
        // const { isFormInit } = formB;
        // isFormInit && toJS(conditionNum).map(c => {
        //     c.items.map((field, index) => {
        //         if (!_.has(formB.fieldMap, WeaTools.getKey(field))) {
        //             console.log("eeeeee",toJS(formB.fieldMap,field))
        //             return true;//xk:渲染有误
        //         }})
        // })
        const nextDataType = this.props.location.query.dataType;
        this.props.proStore.setDataType(nextDataType);
        this.props.proStore.init({ "isSuper":"1","isSuperPage":true,"fromSuperPage":false,"selectedTreeKey":"0",pageFrom:"project",dataType:nextDataType});
    }
    getSearchButtons() {
        const { proStore } = this.props;
        const {clearFormFields} = proStore;
        const btnStyle = {borderRadius: 3, width: 80}
        return [
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@wqtyu6@search`} type="primary" style={btnStyle} onClick={this.forwardQueryResult.bind(this)}>{getLabel(197,"搜索")}</Button>),
            (<span style={{width:'15px', display:'inline-block'}}></span>),
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@hklrlj@reset`} type="ghost" style={btnStyle} onClick={()=>{proStore.clearFormFields()}}>{getLabel(2022,"重置")}</Button>)
        ]
    }
    forwardQueryResult(){
        const { proStore } = this.props;
        const path = "/pro?dataType=3";
        this.context.router.push({
            pathname: "/main/govern"+path
        });
        proStore.setDataType("3")
        proStore.doSearch({ "isSuper":"1","isSuperPage":false,"fromSuperPage":true,"categoryid":"0","isSuperSearch":true,"selectedTreeKey":0,pageFrom:"project",dataType:"3"});
    }
    getRightMenu(){
        let btns = [];
    	btns.push({
            key: "search",
    		icon: <i className='icon-coms-search'/>,
            content: getLabel(197,"搜索"),
            onClick: this.forwardQueryResult.bind(this)
    	});
    	return btns;
    }
}

export default ProSearch;
